package org.jgs1904.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 墨苍璃
 * @date 2022年01月10日14时43分
 */
public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("doGet 方法 调用成功！");

        String method = req.getParameter("method");

        //业务逻辑
        if ("add".equals(method)) {
            req.getSession().setAttribute("msg", "执行了add方法");
        }
        if ("delete".equals(method)) {
            req.getSession().setAttribute("msg", "执行了delete方法");
        }

        // 视图跳转
        req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
